package com.car.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.car.entity.CarPrediction;
import com.car.result.Result;
import com.car.service.CarPredictionService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/api/carPrediction")
public class CarPredictionController {

    @Resource
    private CarPredictionService carPredictionService;

    @GetMapping("brandName")
    public Result<List<String>> brandNameList() {
        LambdaQueryWrapper<CarPrediction> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.select(CarPrediction::getBrandName);

        return Result.ok(carPredictionService.list(queryWrapper).stream()
                .map(CarPrediction::getBrandName).distinct().collect(Collectors.toList()));
    }

    @GetMapping("/yuce/{brandName}")
    public Result<List<CarPrediction>> carPredictionList(@PathVariable String brandName) {
        LambdaQueryWrapper<CarPrediction> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(CarPrediction::getBrandName, brandName);

        return Result.ok(carPredictionService.list(queryWrapper));
    }



}
